package com.mspbots.core.wise.mapper;

import com.mspbots.core.DefaultBaseMapper;
import com.mspbots.core.wise.model.TenantExceptionLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * com.mspbots.core.mapper.SystemExceptionLogMapper
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/7/29
 */
@Mapper
public interface TenantExceptionLogMapper extends DefaultBaseMapper<TenantExceptionLog> {

    /**
     * group by tenant_id,name,type all first log_time
     *
     * @return last model
     */
    @Select(value = "SELECT a.id, a.tenant_id,t.name as tenant_name,a.name,a.type,a.status,a.log_time,a.msg,a.extend " +
            "FROM tenant_exception_logs a,tenant t  WHERE a.id IN (SELECT max(id) AS id FROM tenant_exception_logs GROUP BY tenant_id,name,type) and a.tenant_id = t.id" +
            " ORDER BY a.log_time DESC")
    List<TenantExceptionLog> lastGroupTenantAndName();

    Long selectMinId(Long tenantId);

    Long selectMaxId(Long tenantId);

    Long deleteByMinMaxId(Long tenantId, Long logMinId, Long logMaxId);
}
